﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Xml.Serialization;
using SongSharp.Domain.Data;

namespace SongSharp.Domain.Objects
{
    [Serializable()]
    public class SongSharpState
    {
        private static DataManager DataContext = DataManager.Instance;

        private string CurrentPlaylistUid { get; set; }
        private string CurrentTrackUid { get; set; }
        public int CurrentVolume { get; set; }

        [XmlIgnore]
        public Playlist CurrentPlaylist { get; set; }
        [XmlIgnore]
        public Track CurrentTrack { get; set; }

        public static SongSharpState Get()
        {
            SongSharpState state = DataContext.State;
            if (state != null)
            {
                state.CurrentPlaylist = Playlist.GetByID(state.CurrentPlaylistUid);
                state.CurrentTrack = Track.GetByID(state.CurrentTrackUid);
                
            }
            return state;
        }

        public static void Update(SongSharpState state)
        {
            if (state.CurrentTrack != null)
                state.CurrentTrackUid = state.CurrentTrack.Uid;
            if (state.CurrentPlaylist != null)
                state.CurrentPlaylistUid = state.CurrentPlaylist.Uid;

            DataContext.UpdateSongSharpState(state);
        }
    }
}
